package com.frinder.demo2;

import akka.actor.*;
import com.typesafe.config.ConfigFactory;

/**
 * Created by frinder on 2017/7/24.
 */
public class Main {

//    public static void main(String[] args) {
//        ActorSystem system = ActorSystem.create("Hello", ConfigFactory.load("akka.config"));
//        ActorRef myWork = system.actorOf(Props.create(MyWork.class), "MyWork");
//        ActorRef watchActor = system.actorOf(Props.create(WatchActor.class, myWork), "WatchActor");
//
//        myWork.tell(MyWork.Msg.WORKING, ActorRef.noSender());
//        myWork.tell(MyWork.Msg.DONE, ActorRef.noSender());
//
//        //中断myWork
//        myWork.tell(PoisonPill.getInstance(), ActorRef.noSender());
//    }

    public static void main(String[] args) {
        ActorSystem system = ActorSystem.create("strategy", ConfigFactory.load("akka.config"));
        ActorRef superVisor = system.actorOf(Props.create(SuperVisor.class), "SuperVisor");
        superVisor.tell(Props.create(RestartActor.class), ActorRef.noSender());

        ActorSelection actorSelection = system.actorSelection("akka://strategy/user/SuperVisor/restartActor");//这是akka的路径。restartActor是在SuperVisor中创建的。

        for (int i = 0; i < 100; i++) {
            actorSelection.tell(RestartActor.Msg.RESTART, ActorRef.noSender());
        }
    }

}
